package io.renren.modules.tb.controller;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.modules.sys.controller.AbstractController;
import io.renren.modules.tb.entity.HouseEntity;
import io.renren.modules.tb.service.HouseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;


/**
 * 房源信息
 *
 * @author chengh
 * @email g543391073@gmail.com
 * @date 2019-07-19 16:29:59
 */
@RestController
@RequestMapping("tb/house")
@Api("房源管理接口")
public class HouseController extends AbstractController {
    @Autowired
    private HouseService houseService;

    /**
     * 列表
     */
    @ApiOperation(value = "房源管理列表", response = HouseEntity.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "页码", dataType = "integer", paramType = "query", required = true),
            @ApiImplicitParam(name = "limit", value = "每页条数", dataType = "integer", paramType = "query", required = true),
            @ApiImplicitParam(name = "sidx", value = "排序字段", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "order", value = "排序规则(desc降序、ase升序)", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "username", value = "排序字段", dataType = "string", paramType = "query")
    })
    @GetMapping("/list")
    @RequiresPermissions("tb:house:list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = houseService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("tb:house:info")
    public R info(@PathVariable("id") Long id) {
        HouseEntity house = houseService.getById(id);

        return R.ok().put("house", house);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("tb:house:save")
    public R save(@RequestBody HouseEntity house) {
        houseService.save(house);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("tb:house:update")
    public R update(@RequestBody HouseEntity house) {
        houseService.updateById(house);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("tb:house:delete")
    public R delete(@RequestBody Long[] ids) {
        houseService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
